{include file="public/head"}

<body>
    <div class="dressCard">
        <a href="javascript:;">
            <img src="{$data.goods.image}" alt="图片丢失" class="dressCard-left">
            <div class="dressCard-right">
                <div class="dressCard-right-one">
                    <span>{$data.goods.good_name}</span>
                </div>
                <div class="dressCard-right-three">
                    <div class="dressCard-right-three-left floatLeft">
                        <div class="floatLeft">
                            <span class="redCol">{$data.ass.number}</span>人团
                        </div>
                        <div class="floatLeft"></div>
                        <div class="floatLeft redCol">￥{$data.ass.a_price}</div>
                        <div class="floatLeft">
                            差<span class="redCol">{$data.number}</span>人
                        </div>
                    </div>
                </div>
            </div>
        </a>
    </div>
    <div class="group-wrap">
        <div class="group-t">团长：{$data.user.nickname}</div>
        <img src="{$data.user.headimgurl}" alt="..." />
        {eq name="type" value="4"}
        <div class="count-down">
            拼团已结束！
        </div>
        {else/}
        <div class="count-down">
            还剩
            <div class="down-t" endTime="{:date('Y-m-d H:i:s',$data.end_time)}">
                <i>0</i>:<i>0</i>:<i>0</i>
            </div>
            结束，快来参团吧！
        </div>
        {/eq}
        {switch $type }
        {case 1 }<div class="group-btn share-btn">分享好友</div>{/case}
        {case 2}<a href="/index/assemble/userInfo?id={$data.id}&type=2" class="group-btn">点击参团</a>{/case}
        {case 3}<a href="/index/order/orderList" class="group-btn">你已参与</a>{/case}
        {/switch}
    </div>
    <div class="dressCard-title">猜你喜欢</div>
    <div class="dressCard dressCard-other">
    </div>

    <div class="clickMore">
        查看更多
    </div>

    <div class="share-c">
        <img src="__STATIC__/home/img/share.png" alt="..." />
    </div>


    <script src="__STATIC__/home/js/jquery-2.1.0.js" type="text/javascript" charset="utf-8"></script>
    <script src="__STATIC__/home/js/swiper.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
        $(function () {
            var formatNumber = n => {
                n = n.toString();
                return n[1] ? n : '0' + n;
            }
            // 倒计时
            updateEndTime();
            function updateEndTime() {
                var NowTime = new Date();
                var time = NowTime.getTime();
                $(".down-t").each(function (I) {
                    var endDate = this.getAttribute("endTime");
                    var endDate1 = eval('new Date(' + endDate.replace(/\d+(?=-[^-]+$)/, function (a) { return parseInt(a, 10) - 1; }).match(/\d+/g) + ')');
                    var endTime = endDate1.getTime();
                    var lag = Math.floor((endTime - time) / 1000);
                    //			判断计时是否停止
                    if (lag > 0) {
                        var day = Math.floor(lag / (60 * 60 * 24)); var h = Math.floor(lag / 3600); var d = Math.floor(h / 24); var m = Math.floor(lag / 60 % 60); var s = lag % 60;
                        $(this).html(`<i>${formatNumber(h)}</i>:<i>${formatNumber(m)}</i>:<i>${formatNumber(s)}</i>`);

                    } else {
                        $(this).parent('.count-down').html('拼团已结束');
                    }
                });
                setTimeout(function () {
                    updateEndTime();
                }, 1000);
            };

            var page = 1;
            var limit = 10;
            var is_home = 0;
            // 商品列表接口
            requestList();
            function requestList() {
                $.ajax({
                    type: 'post',
                    url: '/index/goods/goodsListData',
                    data: {
                        page,
                        limit,
                        is_home
                    },
                    success(res) {
                        if (res.code == 1) {
                            var list = res.data || [];
                            var html = '';
                            list.forEach(function (item) {
                                if (item.assemble) {
                                    html += `
									<a href="/index/assemble/assembleInfo?id=${item.id}">
										<img src="${item.image}" alt="图片丢失" class="dressCard-left"/>
										<div class="dressCard-right">
											<div class="dressCard-right-one">
												<span>${item.good_name}</span>
											</div>
											<div class="dressCard-right-two">
												${item.subscription}人已报名
											</div>
											<div class="dressCard-right-three">
												<div class="dressCard-right-three-left floatLeft">
													<div class="floatLeft">
														<span class="redCol">${item.assemble.number}</span>人团
													</div>
													<div class="floatLeft"></div>
													<div class="floatLeft redCol">￥${item.assemble.a_price}</div>
													<div class="floatLeft">
													</div>
												</div>
												<div class="dressCard-right-three-right floatRight">去参团</div>
											</div>
										</div>
									</a>
                                `;
                                } else {
                                    html += `
                                    <a href="/index/goods/goodsInfo?id=${item.id}">
                                        <img src="${item.image}" alt="图片丢失" class="dressCard-left" />
                                        <div class="dressCard-right">
                                            <div class="dressCard-right-one">
                                                <span>${item.good_name}</span>
                                            </div>
                                            <div class="dressCard-right-two">
                                                ${item.subscription}人已报名
                                            </div>
                                            <div class="dressCard-right-three">
                                                <div class="dressCard-right-three-left floatLeft">
                                                    <div class="floatLeft redCol">￥${item.price}</div>
                                                </div>
                                                <div class="dressCard-right-three-right floatRight">去报名</div>
                                            </div>
                                        </div>
                                    </a>
                                `;
                                }
                            });
                            $('.dressCard-other').append(html);
                        } else {
                            $('.clickMore').text('暂无更多数据');
                        }
                    },
                    error() {
                        console.log('商品列表接口错误');
                    }
                })
            };
            // clickMore
            $('.clickMore').click(function () {
                page++;
                requestList();
            });
            // 
            $(document).on('click', '.share-btn', function () {
                $('.share-c').show();
            });
            $(document).on('click', '.share-c img', function () {
                $('.share-c').hide();
            });

        });
    </script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
    <script>
        wx.config({
            debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
            appId: '{$appid}', // 必填，公众号的唯一标识
            timestamp: '{$timestamp}', // 必填，生成签名的时间戳
            nonceStr: '{$noncestr}', // 必填，生成签名的随机串
            signature: '{$signature}',// 必填，签名，见附录1
            jsApiList: [
                'updateAppMessageShareData',
                'updateTimelineShareData'
            ] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
        });
        wx.ready(function () {
            wx.updateAppMessageShareData({
                title: '{$title}', // 分享标题
                desc: '还在等什么？赶紧来和我一起拼团吧！', // 分享描述
                link: '{$url}', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                imgUrl: '{$imgUrl}', // 分享图标
                success: function () {
                }
            });
            wx.updateTimelineShareData({
                title: '{$title}', // 分享标题
                link: '{$url}', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                imgUrl: '{$imgUrl}', // 分享图标
                success: function () {
                },
                cancel: function () {
                }
            });
        });

    </script>
</body>

</html>